package ch.jamme.conf;

import ch.jamme.conf.def.*;

/**
 * This class holds all the strategy objects used to define and customize the behavior of a given marshall process.
 * For any given strategy, if no specific behavior is provided, it returns the predefined default one.
 * @author Mario Fusco
 */
public class MarshallerConfiguration implements Cloneable {
	
	@Override
	public MarshallerConfiguration clone() {
		MarshallerConfiguration clone = new MarshallerConfiguration();
		clone.setFailSafe(isFailSafe());
		clone.setMarshallStyle(getMarshallStyle());
		clone.setClassNormalizer(getClassNormalizer());
		clone.setFieldBindingStrategy(getFieldBindingStrategy());
		clone.setFieldNamingStrategy(getFieldNamingStrategy());
		clone.setFieldPrimitiveStrategy(getFieldPrimitiveStrategy());
		clone.setFieldSuppressionStrategy(getFieldSuppressionStrategy());
		clone.setMarshallerThreadStrategy(getMarshallerThreadStrategy());
		clone.setObjectCreator(getObjectCreator());
		clone.setObjectIntrospector(getObjectIntrospector());
		clone.setObjectToStringConvertor(getObjectToStringConvertor());
		clone.setNamingConvention(getNamingConvention());
		return clone;
	}

	private boolean failSafe = false;
	public boolean isFailSafe() {
		return failSafe;
	}
	public void setFailSafe(boolean failSafe) {
		this.failSafe = failSafe;
	}
	
	private MarshallStyle marshallStyle = MarshallStyle.BIDIRECTIONAL;
	public MarshallStyle getMarshallStyle() {
		return marshallStyle;
	}
	public void setMarshallStyle(MarshallStyle marshallStyle) {
		this.marshallStyle = marshallStyle;
	}
	
	// -- (ClassNormalizer) ---------------------------------------------------
		
	private ClassNormalizer classNormalizer;
	public ClassNormalizer getClassNormalizer() {
		if (classNormalizer == null) classNormalizer = new DefaultClassNormalizer();
		return classNormalizer;
	}
	public void setClassNormalizer(ClassNormalizer classNormalizer) {
		this.classNormalizer = classNormalizer;
	}
	
	// -- (ObjectToStringConvertor) ----------------------------------------------

	private ObjectToStringConvertor objectToStringConvertor;
	public ObjectToStringConvertor getObjectToStringConvertor() {
		if (objectToStringConvertor == null) objectToStringConvertor = new DefaultObjectToStringConvertor();
		return objectToStringConvertor;
	}
	public void setObjectToStringConvertor(ObjectToStringConvertor objectToStringConvertor) {
		this.objectToStringConvertor = objectToStringConvertor;
	}
	
	// -- (ObjectCreator) ----------------------------------------------

	private ObjectCreator objectCreator;
	public ObjectCreator getObjectCreator() {
		if (objectCreator == null) objectCreator = new DefaultObjectCreator();
		return objectCreator;
	}
	public void setObjectCreator(ObjectCreator objectCreator) {
		this.objectCreator = objectCreator;
	}
	
	// -- (ObjectIntrospector) ------------------------------------------------

	private ObjectIntrospector objectIntrospector;
	public ObjectIntrospector getObjectIntrospector() {
		if (objectIntrospector == null) objectIntrospector = new DefaultObjectIntrospector();
		return objectIntrospector;
	}
	public void setObjectIntrospector(ObjectIntrospector objectIntrospector) {
		this.objectIntrospector = objectIntrospector;
	}

	// -- (FieldSuppressionStrategy) ------------------------------------------
	
	private FieldSuppressionStrategy fieldSuppressionStrategy;
	public FieldSuppressionStrategy getFieldSuppressionStrategy() {
		if (fieldSuppressionStrategy == null) fieldSuppressionStrategy = new DefaultFieldSuppressionStrategy();
		return fieldSuppressionStrategy;
	}
	public void setFieldSuppressionStrategy(FieldSuppressionStrategy fieldSuppressionStrategy) {
		this.fieldSuppressionStrategy = fieldSuppressionStrategy;
	}

	// -- (FieldBindingStrategy) ------------------------------------------
	
	private FieldBindingStrategy fieldBindingStrategy;
	public FieldBindingStrategy getFieldBindingStrategy() {
		if (fieldBindingStrategy == null) fieldBindingStrategy = new DefaultFieldBindingStrategy();
		return fieldBindingStrategy;
	}
	public void setFieldBindingStrategy(FieldBindingStrategy fieldBindingStrategy) {
		this.fieldBindingStrategy = fieldBindingStrategy;
	}
	
	// -- (FieldPrimitiveStrategy) ------------------------------------------
	
	private FieldPrimitiveStrategy fieldPrimitiveStrategy;
	public FieldPrimitiveStrategy getFieldPrimitiveStrategy() {
		if (fieldPrimitiveStrategy == null) fieldPrimitiveStrategy = new DefaultFieldPrimitiveStrategy();
		return fieldPrimitiveStrategy;
	}
	public void setFieldPrimitiveStrategy(FieldPrimitiveStrategy fieldPrimitiveStrategy) {
		this.fieldPrimitiveStrategy = fieldPrimitiveStrategy;
	}

	// -- (FieldNamingStrategy) ------------------------------------------
	
	private FieldNamingStrategy fieldNamingStrategy;
	public FieldNamingStrategy getFieldNamingStrategy() {
		if (fieldNamingStrategy == null) fieldNamingStrategy = new DefaultFieldNamingStrategy();
		return fieldNamingStrategy;
	}
	public void setFieldNamingStrategy(FieldNamingStrategy fieldNamingStrategy) {
		this.fieldNamingStrategy = fieldNamingStrategy;
	}

	// -- (MarshallerThreadStrategy) ------------------------------------------
	
	private MarshallerThreadStrategy marshallerThreadStrategy;
	public MarshallerThreadStrategy getMarshallerThreadStrategy() {
		if (marshallerThreadStrategy == null) marshallerThreadStrategy = new DefaultMarshallerThreadStrategy();
		return marshallerThreadStrategy;
	}
	public void setMarshallerThreadStrategy(MarshallerThreadStrategy marshallerThreadStrategy) {
		this.marshallerThreadStrategy = marshallerThreadStrategy;
	}

	// -- (NamingConvention) ------------------------------------------
	
	private NamingConvention namingConvention;
	public NamingConvention getNamingConvention() {
		if (namingConvention == null) namingConvention = new DefaultNamingConvention();
		return namingConvention;
	}
	public void setNamingConvention(NamingConvention namingConvention) {
		this.namingConvention = namingConvention;
	}
}